<!DOCTYPE HTML>
<html>
<!--_meta 作为公共模版分离出去-->
{include file="common/_meta"}
<!--/meta 作为公共模版分离出去-->

<body>
<!--_header 作为公共模版分离出去-->
{include file="common/_header"}
<!--/_header 作为公共模版分离出去-->
<!--_menu 作为公共模版分离出去-->
{include file="common/_menu"}
<!--/_menu 作为公共模版分离出去-->

<section class="Hui-article-box">
    {include file="common/_nav"}
	<div class="Hui-article">
        <div class="pos-a" style="width:150px;left:0;top:70px; height:40%; border-right:1px solid #e5e5e5; background-color:#f5fafe">
<!-- 选择栏目浏览 -->
            <dl id="select-menu-article" >
                <dt style="margin-top: 60px; margin-left: 20px;height:40px;font-size:20px; "> <a href="{:url($action)}">所有文章列表</a></dt>
                <dd>
                    <ul>
                        {foreach $category_name_tree as $value}
                        <li style="margin-left: 10px;height:30px; "><a href="{:url($action,'cate_id='.$value.id)}" >{$value.category_name}</a></li>
                            {notempty name="value._child"}
                            {foreach  $value._child  as $val}
                            <li style="margin-left: 30px;height:30px; "><a href="{:url($action,'cate_id='.$val.id)}" >{$val.category_name}</a></li>
                                {notempty name="val._child"}
                                {foreach  $val._child  as $va}
                                <li style="margin-left: 30px;height:30px; "><a href="{:url($action,'cate_id='.$va.id)}" >{$va.category_name}</a></li>
                                {/foreach}
                                {/notempty}
                            {/foreach}
                            {/notempty}
                        {/foreach}  
                    </ul>
                </dd>
            </dl>
        </div>
        <div style="margin-left:150px;">
        <div class="pd-20">
            <form action="searcher" method="get" >
                <div class="text-l" style="margin-left:20%">
                    日期范围：
                    <input type="date" id="logmin" name="logmin" value="{notempty name="searcher"}{$searcher.logmin}{/notempty}" class="input-text Wdate" style="width:150px;">
                    -
                    <input type="date" id="logmax" name="logmax" value="{notempty name="searcher"}{$searcher.logmax}{/notempty}" class="input-text Wdate" style="width:150px;">
                    <input type="text" id="title" name="title" value="{notempty name="searcher"}{$searcher.title}{/notempty}"  placeholder="标题" style="width:250px" class="input-text">
                    <button name="" id="" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜文章</button>
                    <button name="" id="" class="btn btn-success" type="reset"><i class="Hui-iconfont">&#xe66c;</i>清空条件</button>
                </div>
            </form>
            <div class="cl pd-5 bg-1 bk-gray mt-20"> 
                <span class="l">
                    <a href="javascript:;" onclick="delAll()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
                    <a href="javascript:;" onclick="dutyAll()" class="btn btn-success radius"><i class="Hui-iconfont">&#xe6e1;</i> 批量审核</a> 
                    <a href="{:url('article/add','cate_id='.$cate_id)}" class="btn btn-primary radius" ><i class="Hui-iconfont">&#xe600;</i>添加文章</a>
                </span> 
                <span class="r">共有数据：<strong>{$counts}</strong> 条</span> 
            </div>
            <div class="mt-20">
                <table class="table table-border table-bordered table-bg table-hover table-sort">
                    <thead>
                        <tr class="text-c">
                            <th width="20"><input type="checkbox" value=""  name="allcheck"></th>
                            <th width="30">ID</th>
                            <th width="80">缩略图</th>
                            <th width="25%">文章标题</th>
                            <th width="120px">更新日期</th>
                            <th width="120px">栏目</th>
                            <th width="60px">发布人</th>
                            <th width="60px">作者</th>
                            <th width="60px">来源</th>
                            <th width="60px">审核状态</th>
                            <th width="120px">审核日期</th>
                            <th width="60">点击次数</th>                            
                            <th width=>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach $data as $val}
                        <tr class="text-c va-m" style="height:80px;">
                            <td><input type="checkbox" value="{$val.id}" name="checkbox[]"></td>
                            <td>{$val.id}</td>
                            <td><img width="60" class="product-thumb" src="{$val.thumb}"></td>
                            <td class="text-l">
                                <a  href="javascript:article_show('文章详情','{:url(\'preview\',\'id=\'.$val.id)}');" style="text-decoration:none" >{$val.title}</a>
                            </td>
                            <td class="text-l">{$val.pubtime|date="Y-m-d H:i:s",###}</td>
                            <td class="text-c">{$val.cate_id|get_category_name}</td>
                            <td class="text-c">{$val.uid|get_adminuser_name}</td>
                            <td class="text-c">{$val.writer}</td>
                            <td class="text-c">{$val.source}</td>
                            {switch name="val.ispost"}
                                {case value="1"}
                            <td class="td-status"><a href="javascript:void(0);" title="撤销审核" onClick="dutyDown(this,'{$val.id}')" ><span class="label label-success radius">已过审</span></a></td>
                            <td class="td-time">{$val.dutytime|date="Y-m-d H:i:s",###}</td>
                                {/case}
                                {case value="2"}
                            <td class="td-status"><a href="javascript:void(0);" title="通过审核" onClick="dutyUp(this,'{$val.id}')" ><span class="label label-danger radius">未通过</span></a></td>
                            <td class="td-time">{$val.dutytime|date="Y-m-d H:i:s",###}</td>
                                {/case}
                                {default /}
                            <td class="td-status"><a href="javascript:void(0);" title="审核文章" onClick="duty(this,'{$val.id}')" ><span class="label label-error radius">未审核</span></a></td>
                            <td class="td-time"></td>
                            {/switch}
                            <td>{$val.clicks}</td>
                            <td class="td-manage">
                                <a href="javascript:;" title="查看" style="text-decoration:none"  onClick="article_show('文章详情','{:url(\'preview\',\'id=\'.$val.id)}')"><i class="Hui-iconfont">&#xe685;</i></a> 
                                <a href="{:url('edit','id='.$val.id)}" title="编辑" style="text-decoration:none" class="ml-10"><i class="Hui-iconfont">&#xe6df;</i></a> 
                                <a href="javascript:;" title="删除" style="text-decoration:none" class="ml-10" onClick="delOne(this,'{$val.id}')" ><i class="Hui-iconfont">&#xe6e2;</i></a>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
            </div>
            <div class="cl pd-5 bg-1 bk-gray mt-20  pagin">
                <div class="message">共<i class="blue">{$pages}</i>页 | <i class="blue">{$counts}</i>条记录, 当前显示第&nbsp;<i class="blue nowpage"></i>页</div>
                {$data->render()}
            </div>
        </div>
        </div>
	</div>
</section>

<!--_footer 作为公共模版分离出去-->
{include file="common/_footer" /}
<!--/_footer 作为公共模版分离出去-->
<!-- <script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script> -->
<!-- 请在下方写此页面业务相关的脚本 -->
<script type="text/javascript">
//显示当前页
var nowpage=$('.active').children('span').text();
nowpage = nowpage=="" ? 1 : nowpage;
$(".nowpage").html(nowpage);

//logmax日期不能比logmin小,logmin和loginmax不能超过当前日期
$("#logmax").change(function(){
    var logmin=$("#logmin").val();
    var logmax=$("#logmax").val();

    var today=new Date()
    var y = today.getFullYear();
    var m = today.getMonth()+1;
    var d = today.getDate();
    console.log(logmin);
    console.log(logmax);
    var now=y+'-'+m+'-'+d;
    if(now<logmin){
        $("#logmin").val(now);
        $("#logmax").val(now);
        return false;
    }
    if(logmax<logmin){
        $("#logmax").val(logmin);
        return false;
    }
})
//清除条件


/*文章-审核*/
function duty(obj,id){
	layer.confirm('审核文章？', {
		btn: ['通过','不通过','取消'],
		shade: false
	},
	function(){
        pass(obj,id);
	},function(){
		reject(obj,id);
	},function(){
        return false;
    });
}

/*文章-通过审核*/
function pass(obj,id){
    $.post('duty',{'id':id,'ispost':1},function(data){
        if(data.status==1){
            $(obj).parents("tr").find(".td-time").html(data.time);
            $(obj).parents("tr").find(".td-status").html('<a href="javascript:void(0);" title="撤销审核" onClick="dutyDown(this,'+id+')" ><span class="label label-success radius">已过审</span></a>');
            $(obj).remove();
            layer.msg('操作成功', {icon:6,time:1000});
        }else{
            layer.msg('操作失败', {icon:5,time:1000});
        }
    },'json');
}
function dutyUp(obj,id){
	layer.confirm('确认通过审核？',function(index){
        pass(obj,id);
	});
}
/*文章-批量审核通过*/
function dutyAll(){
	layer.confirm('确认通过审核？',function(index){
        var checkbox = $('.text-c input[name="checkbox[]"]') ;
        checkbox.each(function(x){
            if(this.checked){
                var obj=$(this).parents('tr').find('.td-status').children('a');
                var id=$(this).val();
                pass(obj,id);
            }
        })
	});
}

/*文章-撤销审核*/
function reject(obj,id){
    $.post("{:url('article/duty')}",{'id':id,'ispost':2},function(data){
        if(data.status==1){
            $(obj).parents("tr").find(".td-time").html(data.time);
            $(obj).parents("tr").find(".td-status").html('<a href="javascript:void(0);" title="通过审核" onClick="dutyUp(this,'+id+')" ><span class="label label-danger radius">未通过</span></a>');
            $(obj).remove();
            layer.msg('操作成功', {icon:6,time:1000});
        }else{
            layer.msg('操作失败', {icon:5,time:1000});
        }
    },'json');
}
function dutyDown(obj,id){
	layer.confirm('确认撤销审核？',function(index){
		reject(obj,id);
	});
}

/*文章-查看*/
function article_show(title,url){ 
	layer_show(title, url);
}

/*文章-编辑*/
function product_edit(title,url,id){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}

/*文章-删除*/
function del(id){
    $test=$.post("{:url('article/del')}",{'id':id},function(data){
        if(data.status==1){
            return true;
        }else{
            return false;
        }
    },'json');
    return $test;
}
function delOne(obj,id){
	layer.confirm('确认要删除吗？',function(index){
        if(del(id)){
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});
        }else{
            layer.msg('删除失败!',{icon:2,time:1000});
        }
	});
}
//批量删除
function delAll(){
	layer.confirm('确认删除？',function(index){
        var checkbox = $('.text-c input[name="checkbox[]"]');
        var ids = new Array();
        checkbox.each(function(x){
            if(this.checked){
                ids.push(this.value);
            }
        });
        if(del(ids)){
            $.each(ids,function(x,val){
                obj= $('.text-c input[value="'+val+'"]');
                $(obj).parents("tr").remove();
            });
            layer.msg('删除成功!',{icon:1,time:1000});
        }else{
            layer.msg('删除失败!',{icon:2,time:1000});
        }
	});
}

</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>